<template>
  <div class="recycle-task-item">
    <div class="task-info">
      <h3>{{ task.title }}</h3>
      <p>{{ task.desc }}</p>
      <div class="tags">
        <span class="priority-tag" :class="task.priority">
          {{ task.priority }}
        </span>
        <span class="deadline">截止日期: {{ task.deadline }}</span>
      </div>
    </div>
    <div class="actions">
      <button @click="restoreTask" class="restore-btn">恢复任务</button>
      <button @click="permanentlyDelete" class="delete-btn">彻底删除</button>
    </div>
  </div>
</template>

<script setup lang="ts">
import { defineProps } from 'vue';
import { useTaskStore } from '@/store/taskStore';

const props = defineProps<{
  task: {
    id: number;
    title: string;
    desc: string;
    priority: 'low' | 'medium' | 'high';
    isDone: boolean;
    deleted: boolean;
    deadline: string;
  }
}>();

const taskStore = useTaskStore();

// 恢复任务
const restoreTask = () => {
  taskStore.restoreFromRecycleBin(props.task.id);
};

// 永久删除
const permanentlyDelete = () => {
  if (confirm('确定要彻底删除此任务吗？此操作不可恢复！')) {
    taskStore.permanentlyDelete(props.task.id);
  }
};
</script>

<style scoped>
.recycle-task-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 16px;
  margin: 10px 0;
  border-radius: 8px;
  background: white;
  box-shadow: 0 2px 5px rgba(0,0,0,0.1);
  opacity: 0.7;
}
.restore-btn {
  background: #28a745;
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
}
.delete-btn {
  background: #dc3545;
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
  margin-left: 8px;
}
.priority-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  margin-right: 8px;
  font-size: 12px;
  color: white;
}
.low { background: #6c757d; }
.medium { background: #ffc107; }
.high { background: #dc3545; }
</style>